<?php

namespace Admin\Controller;

use Think\Controller;

class OrderController extends RootController {

    protected $_page_size = 20;
    
    public function order_list()
    {
        $page = I('get.p', 1);
        $Order = M('Order');
        $count = $Order->where(['status' => 1])->count();

        $where['a.status'] = 1;
        if (I('post.service')) {
            $where['a.service'] = I('post.service');
        }

        if (I('post.mch_id')) {
            $where['a.mch_id'] = I('post.mch_id');
        }

        $list = $Order->field('a.*, b.name, c.username')
            ->table('t_order a')
            ->join('t_channel b ON a.service = b.type', 'left')
            ->join('t_account c ON a.mch_id = c.mch_id', 'left')
            ->where($where)
            ->limit(($page - 1) * $this->_page_size . ',' . $this->_page_size)
            ->select();
        $this->list = $list;

        $Page = new \Think\Page($count, 20);
        $show = $Page->show();
        
        $Channel = M('Channel');
        $channel_list = $Channel->where(['status' => 1])->select();
        $this->assign('channel_list', $channel_list);

        $Account = M('Account');
        $account_list = $Account->where(['status' => 1])->select();
        $this->assign('account_list', $account_list);

        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display();
    }
}
